package com.gz.service.impl;

import com.gz.entity.PaperUser;
import com.gz.dao.PaperUserMapper;
import com.gz.service.PaperUserService;
import org.springframework.stereotype.Service;
import com.gz.dto.PaperUserDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gz.dto.PageData;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
 * 试卷用户关系表(PaperUser)表服务实现类
 *
 * @author jhk
 * @since 2024-09-26 00:56:46
 */
@Service
public class PaperUserServiceImpl implements PaperUserService {
    @Autowired
    private PaperUserMapper paperUserDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PaperUser queryById(Integer id) {
        return paperUserDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param dto 筛选条件
     * @return 查询结果
     */
    @Override
    public PageData queryByPage(PaperUserDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<PaperUser> list = paperUserDao.queryAllByLimit(dto);
        PageInfo<PaperUser> pageInfo = new PageInfo<>(list);
        return new PageData<>(pageInfo.getTotal(), list);
    }
    @Override
    public List<PaperUser> queryAll(PaperUserDto dto){
        List<PaperUser> list = paperUserDao.queryAll(dto);
        return list;
    }
    /**
     * 新增数据
     *
     * @param paperUser 实例对象
     * @return 实例对象
     */
    @Override
    public PaperUser insert(PaperUser paperUser) {
        paperUserDao.insert(paperUser);
        return paperUser;
    }
    @Override
    public int insertBatch(List<PaperUser> paperUsesr) {
        int i = paperUserDao.insertBatch(paperUsesr);
        return i;
    }
    /**
     * 新增数据
     *
     * @param paperUser 实例对象
     * @return 实例对象
     */
    @Override
    public PaperUser insertSelective(PaperUser paperUser) {
        paperUserDao.insertSelective(paperUser);
        return paperUser;
    }

    /**
     * 修改数据
     *
     * @param paperUser 实例对象
     * @return 实例对象
     */
    @Override
    public PaperUser update(PaperUser paperUser) {
        paperUserDao.update(paperUser);
        return queryById(paperUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return paperUserDao.deleteById(id) > 0;
    }
}
